package com.example.wujinapi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.wujinapi.dao.FirsttypeDao;
import com.example.wujinapi.dao.ThirdtypeDao;
import com.example.wujinapi.entity.Firsttype;
import com.example.wujinapi.entity.Secondtype;
import com.example.wujinapi.entity.Thirdtype;
import com.example.wujinapi.service.ThirdtypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * (Thirdtype)表服务实现类
 *
 * @author makejava
 * @since 2023-07-15 17:34:22
 */
@Service("thirdtypeService")
public class ThirdtypeServiceImpl extends ServiceImpl<ThirdtypeDao, Thirdtype> implements ThirdtypeService {

    @Autowired
    private ThirdtypeDao thirdtypeDao;

    @Override
    public void addThirdtype(Thirdtype thirdtype) {
        Thirdtype Data=thirdtypeDao.selectOne(new QueryWrapper<Thirdtype>().eq("thirdclass", thirdtype.getThirdclass()));
        if(Data==null){ //为空才插入新用户
            thirdtypeDao.insert(thirdtype);
        }
    }

    @Override
    public void updateThirdClass(int firstClassId, String beforFirstName, String firstClassName) {
        Thirdtype fData=thirdtypeDao.selectOne(new QueryWrapper<Thirdtype>().eq("firstid",firstClassId).eq("firstclass",beforFirstName));
        if(fData!=null){
            fData.setFirstclass(firstClassName);
            thirdtypeDao.updateById(fData);
        }
    }

    @Override
    public void deleteThirdtype(int dataId) {
        thirdtypeDao.delete(new QueryWrapper<Thirdtype>().eq("id",dataId));
    }

    @Override
    public List<Thirdtype> getThirdtypes() {
        List<Thirdtype> listDatas=thirdtypeDao.selectList(new QueryWrapper<Thirdtype>().orderByDesc("thirdsortnum"));
        return listDatas!=null?listDatas:null;
    }

    @Override
    public List<Thirdtype> getThirdtypesByFirstIdAndSecondId(int firstId, int secondId) {
        List<Thirdtype> listDatas=thirdtypeDao.selectList(new QueryWrapper<Thirdtype>().eq("firstid",firstId).eq("secondid",secondId).orderByDesc("thirdsortnum"));
        return listDatas!=null?listDatas:null;
    }
}

